<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <div>{{reverString}}</div>
        <div>{{reverString}}</div>
        <div>{{reverseMessage()}}</div>
        <div>{{reverseMessage()}}</div>
    </div>
    <script src="js/vue.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                msg: 'hello',
                num: 100
            },
            //计算属性与方法的区别:计算属性是基于依赖进行缓存的，而方法不缓存
            methods: {
                reverseMessage: function() {
                    console.log('methods');
                    return this.msg.split('').reverse().join('');
                }
            },
            computed: {
                reverString: function() {
                    console.log('computed');
                    var total = 0;
                    for (var i = 0; i <= this.num; i++) {
                        total += i;
                    }
                    return total;
                }
            }
        });
    </script>
</body>

</html>